In This Part
by Kenn Scribner
In This Chapter
In a nutshell, OpenGL is a programmers interface for developing interactive graphics-based applications. Although you can do simple two-dimensional (2D) work with OpenGL, it was really designed to work within the three-dimensional (3D) graphical display world. With relatively little effort on your part, you can render (draw) 3D objects and worlds, complete with lighting effects, aliasing, blending, and even fog. Ill be discussing these terms throughout this chapter, so dont be too concerned if you dont understand their meaning at this point. One thing to remember is that OpenGL itself provides you with the tools you require to easily build and display complex 3D scenes. It doesnt supply the models!
Tip:Though OpenGL itself doesnt come complete with ready-made models for you to use, there is an auxiliary OpenGL library that ships with practically every OpenGL implementation, including Microsofts. Youll use this library to display some stunning shapes when you reach the first sample program.
Where did OpenGL originate, and why? To answer this, step back in time to the late 1980s. At that time, Silicon Graphics (SGI) dominated the high-end graphics processing market. Its true forte was custom innovative graphics processors, which accelerated the rendering speeds of its systems. But SGI knew hardware alone wasnt the answer. To sell systems, people needed to be able to program the processors easily. Therefore, SGI developed a graphics language, known as GL. GL was platform-specific, though, and it carried the additional burden of managing user interface elements. Although SGI wanted a language to express complex graphics, it ended up with a language that also managed mouse events and windows.
As GL grew, it became increasingly difficult to use. It wasnt that the graphical nature of the language was so difficult; the difficulty was with managing the user interface. Because SGI systems were UNIX-based, the systems also carried SGIs implementation of X Window (a popular open-system user interface standard still prevalent today in UNIX systems). SGI decided it was not wise to develop and maintain two parallel user interface implementations. Thus, OpenGL was born. SGI removed the user interface support from GL and forged a new graphical interface language that was lean and mean, at least when compared to its predecessor.
OpenGL is now an international standard that may be found on a wide range of systems. Windows NT and Windows 98 ship with OpenGL as a part of the basic operating system, and even Windows 95 Service Release 2 added OpenGL support as standard equipment.
Note:Those of you still using early releases of Windows 95 arent out in the cold. Microsoft released OpenGL for Windows 95 and made it freely available in a self-extracting archive. You may download it from ftp://ftp.microsoft.com/softlib/mslfiles/opengl95.exe.
So you now know OpenGL is a programmers interface for graphics programming, and youve read a bit of its history. Now I will turn to the core essence of OpenGL. If youve never studied the mathematics behind 3D computer graphics, you might not truly appreciate what OpenGL does for you (dont let that stop you from using it, however). The mathematics involves several successive transformations using transformation matrices, which naturally involve matrix algebra. Youll see a bit of this in a moment when you look at some of the most basic graphics concepts. OpenGL, however, manages much of the mathematics for you, allowing you to concentrate on the real problem at handyour graphical scene. OpenGL, then, is really a mathematical state machine that captures the math behind graphics programming as well as some of the other basic fundamentals, such as double buffering (writing to separate graphics memory buffers for animation purposes). If you have one of the newer-generation 3D graphics accelerator video cards, its hardware probably supports OpenGL and the processing (and memory management) OpenGL must undertake to successfully render a scene even more quickly.
This is a book about programming, but Id be remiss if I didnt spend some time describing some core terms and key concepts you absolutely must understand before you attempt your first 3D masterpiece. Youll begin by exploring some fundamental graphics programming terms and then youll move into some basic theory.
To begin your look at OpenGL, you need to have a good understanding of the graphics programmers language. Not their programming language, such as C++, but rather the way they speak. When they talk about their models and translations, you need to understand what they are talking about. So I will start with some core terms.
Model. When I talk about a model, Im talking about an individual object within my (typically) 3D scene. Perhaps I have a model of a cube, or maybe a sphere. I could even have a model of a 3D Tyrannosaurus rex.
Polygons. A 3D surface appears to be solid, but it is really composed of several shapes (usually triangles for theoretical reasons). The triangles are arranged in a mesh, and the area within the polygon is left alone (wireframe), shaded (colored in, with or without lighting effects), or texture-mapped (external image applied). Wireframe is just thatthe model is drawn using only lines. If you apply shading, or light properties, you fill in the area of the polygon with a color. If the polygons are numerous enough, and if your system has a large color palette, you can render terrific-looking, highly detailed models. The ultimate in polygon surface effects is texture-mapping, where you apply a decal (texture) to the polygon. The decal is typically a bitmapped image you create beforehand. You conform (distort) the decal to the polygon surface, thus making the polygon itself appear to be much more complex than it really is.
Normals. The polygons OpenGL accepts lie in a plane (the vertices are coplanar). The polygons surface normal is a vector that resides in the third coordinate plane tangent to the surface of the polygon. Imagine that the top of your desk is a polygon. If you were to stand a sharpened pencil eraser down on the desk, the pencil would represent the desktops polygonal (surface) normal. Normals, and their proper calculation, are critical for light calculations.
Translation. Translation means moving the model (intact) from one set of coordinates to another. Essentially, youre relocating your model to another location within the scene.